using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading; 
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;
using Microsoft.Advertising.Mobile.Xna;
using System.Diagnostics;

namespace MeteorShower
{
    //THIS IS A TEST
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    /// 
    public class Game1 : Microsoft.Xna.Framework.Game
    {

        private static GameView gameView;
        private static MainMenuView mainMenuView;
        private static GameOverView gameOverView;
        static private String gameState = "mainmenuview";
        GraphicsDeviceManager graphics;
        private static int highScore;
        private static int score;
        private static theme currentTheme;
        private static theme [] themeArray = {new altTheme(), new standardTheme()};

        public Game1()
        {
            
            highScore = 0;
            score = 0;
            currentTheme = themeArray[0];

            graphics = new GraphicsDeviceManager(this);
          
            graphics.IsFullScreen = true;
            Content.RootDirectory = "Content";

            gameView = new GameView(this);
            gameView.reset();
            mainMenuView = new MainMenuView(this);
            gameOverView = new GameOverView(this);
   
            Components.Add(gameView);
            Components.Add(mainMenuView);
            Components.Add(gameOverView);

            TargetElapsedTime = TimeSpan.FromTicks(333333);
        }

        public static void changeTheme()
        {
            Debug.WriteLine("theme number " + (Array.IndexOf(themeArray, currentTheme)));
            currentTheme = themeArray[(Array.IndexOf(themeArray ,currentTheme)+1)%(themeArray.Length)];
            mainMenuView.reloadContent();
            gameView.reloadContent();
            gameOverView.reloadContent();
            //currentTheme = themeArray[1]; 
        }

        static public void setGameState(String newState)
        {
            gameState = newState;
        }

        static public void setHighScore(int score)
        {
            highScore = score;
        }

        static public int getHighScore()
        {
            return highScore;
        }

        static public void setScore(int newScore)
        {
            score = newScore;
        }

        static public int getScore()
        {
            return score;
        }

        static public String getGameState()
        {
            return gameState;
        }

        protected override void Initialize()
        {
            //Initialize can carry logic not only to help start the class, but also to reset it in the circumstance of a Game Over or similar event
            base.Initialize();
        }

        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        static public void reset()
        {
            gameView.reset();
        }

        protected override void Update(GameTime gameTime)
        {
            if (getGameState().Equals("exit"))
            {
                this.Exit();
            }
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }

        static public theme getTheme()
        {
            return currentTheme;
        }
    }
}
